home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 1
/
Gekikoh Dennoh Club Vol. 1 (Japan).7z
/
Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin
/
kowin
/
archive
/
net
/
chatwins.lzh
/
hist.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-09
|
1KB
|
83 lines
/* Copyright 1993 H.Ogasawara (COR.) */
#include <corlib.h>
#define MAXCHAR 160
typedef struct _hist {
char *line;
struct _hist *next;
} T_HIST;
char savebuf[MAXCHAR+2];
T_HIST curline= { savebuf, NULL };
T_HIST *lasthp= NULL;
static T_HIST *
prevent( pp )
T_HIST *pp;
{
T_HIST *hp, *prevp= NULL;
for( hp= lasthp ; pp != hp && hp ; prevp= hp, hp= hp->next );
return prevp;
}
addhist( msg )
char *msg;
{
int i;
char *ptr;
T_HIST *hp;
if( *msg == '\0' || *msg == '\r' || *msg == '\n' )
return TRUE;
if( lasthp && !strcmp( msg, lasthp->line ) )
return TRUE;
if( lasthp == &curline )
lasthp= lasthp->next;
for(;;){
if( hp= (void*)malloc( sizeof(T_HIST)+strlen(msg)+2 ) ){
ptr= ((char*)hp)+sizeof(T_HIST);
strcpy( ptr, msg );
hp->line= ptr;
hp->next= lasthp;
lasthp= hp;
return TRUE;
}
if( lasthp ){
for( hp= lasthp ; hp->next ; hp= hp->next );
if( hp= prevent( hp ) ){
free( hp->next );
hp->next= NULL;
continue;
}
}
return FALSE;
}
}
getnexthist( ibuf, histflag, dd )
char *ibuf;
{
static T_HIST *hp;
if( !histflag ){
if( lasthp != &curline )
curline.next= lasthp;
hp= lasthp= &curline;
strcpy( savebuf, ibuf );
}
if( dd ){
if( hp->next ){
hp= hp->next;
strcpy( ibuf, hp->line );
}
}else{
if( prevent( hp ) ){
hp= prevent( hp );
strcpy( ibuf, hp->line );
}
}
}